/*
 Copyright 2012 Sven-Ove Bjerkan

 This file is part of KO-Ozi.

 KO-Ozi is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 KO-Ozi is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with KO-Ozi. If not, see <http://www.gnu.org/licenses/>.
 */
package com.koozi.ui;

import java.io.File;
import java.io.IOException;
import javax.swing.filechooser.FileSystemView;

/**
 *
 * @author Sven-Ove Bjerkan
 */
public class DirectoryRestrictedFileSystemView extends FileSystemView {

    private final File[] rootDirectories;

    public DirectoryRestrictedFileSystemView(File rootDirectory) {
        super();
        this.rootDirectories = new File[]{rootDirectory};
    }

    public DirectoryRestrictedFileSystemView(File[] rootDirectories) {
        this.rootDirectories = rootDirectories;
    }

    @Override
    public File[] getRoots() {
        return rootDirectories;
    }

    @Override
    public boolean isRoot(File file) {
        for (File root : rootDirectories) {
            if (root.equals(file)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public File getHomeDirectory() {
        return rootDirectories[0];
    }

    @Override
    public File createNewFolder(File containingDir) {
        File folder = new File(containingDir, "New Folder");
        folder.mkdir();
        return folder;
    }
}
